# -*- coding: utf-8 -*-
"""
Contains a function to test exact GARP.
"""

    
def garp_exact(C,P):
    '''Test for eact GARP. No CCEI.'''
    V = C @ P.T
    N = V.shape[0] #Number of obs
    
    #This loop will see if there are any cycles.
    for n in range(N):
        #Check if there is a cycle involving ob n.
        visited = N * [False] #If an element enters here we disregard it.
        queue = [n] #Observations left to check.
        while len(queue):
            m = queue.pop() #We will see what ob m is e-revealed preferred to
            for i in range(N):
                #The for loop does not consider obs we know aren't in a cycle.
                if (visited[i] == False) & ( i != m ): #Only check out obs that haven't been visited
                    if V[m,m] >= V[i,m]: #See if weak rp
                        #m is e-revealed preferred to i
                        if i == n: #If i is n then we've found a cycle unless the rp is weak.
                            if V[m,m] > V[n,m]:
                                return False
                        queue.append(i) #We know there's a path from n to i. 
                        visited[i] = True
    return True
